#-*-encoding=utf-8-*-
@script_attr(permission='zope.Public',use_template=False)
def index():
    """首页

这是应用的首页"""

    max_per_folder = 5#每个文件夹显示的文件数
    folder_obj = intids.getObject(appletsetting['location'])
    result = {}
    
    for foldername, folder in folder_obj.items():
        if IFolder.providedBy(folder):
            all_files = []
            cur_count = 0
            for filename, file in folder.items():
                if IFolder.providedBy(file):
                    continue
                file_info = {}
                file_info['name'] = filename
                file_info['down_url'] = absoluteURL(file, request)
                all_files.append(file_info)
                cur_count = cur_count + 1
                if cur_count >= max_per_folder:
                    break;
            result[foldername] = (all_files, str(intids.getId(folder)))
    return render_template('list_file', result = result)
    

@script_attr(permission='zope.Public',use_template=False)
def more():
    """Morefiles

None"""

    folder_id = request.get('folder', None)
    if not folder_id:
        return u'请输入文件夹名字'
    
    folder = intids.getObject(int(folder_id))
    result = []
    for name, file in folder.items():
        file_info = {}
        file_info['name'] = name
        file_info['down_url'] = absoluteURL(file, request)
        result.append(file_info)
    
    return render_template('more_template', request = request, result = result, folder=folder)
    

